import { RouteRecordRaw, createRouter, createWebHashHistory } from 'vue-router'

export const homePageRoute = {
  path: '/',
  name: 'home',
  meta: { title: '首页' },
  component: () => import('../views/home/Index.vue'),
}

/** 白名单 */
export const whitelistRouterMap = [
  homePageRoute,
  {
    path: '/404',
    name: '404',
    meta: { title: '404' },
    component: () => import('../views/404/Index.vue'),
  },
  // { path: '/:pathMatch(.*)', redirect: '/404', } // vue3的对404的配置不能直接使用*，需要用正则匹配
]

export const routes: Array<RouteRecordRaw> = [
  ...whitelistRouterMap
]

/** 动态路由map */
export const asyncRouterMap = [
  {
    path: '/auth',
    name: 'auth',
    meta: { title: '用户' },
    component: () => import('../views/auth/Index.vue'),
  },
  {
    path: '/artical',
    name: 'artical',
    meta: { title: '文章' },
    component: () => import('../views/artical/Index.vue'),
  },
]


const router = createRouter({
  // 4. 内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。
  history: createWebHashHistory(),
  routes, // `routes: routes` 的缩写
})

export default router
